package com.todo.todolist.Entity;

import lombok.Data;
import org.springframework.stereotype.Component;

@Data
@Component
public class ResultData {
    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;
    private static final String SUCCESS_R = "操作成功！";
    private static final String ERROR_R = "操作失败！";


    private int code;
    private String msg;
    private Object data;

    public ResultData() {}

    public static ResultData success()
    {
        ResultData r = new ResultData();
        r.setCode(SUCCESS_CODE);
        r.setMsg(SUCCESS_R);
        return r;
    }

    public static ResultData success(Object data)
    {
        ResultData r = new ResultData();
        r.setCode(SUCCESS_CODE);
        r.setMsg(SUCCESS_R);
        r.setData(data);
        return r;
    }

    public static ResultData success(String msg)
    {
        ResultData r = new ResultData();
        r.setCode(SUCCESS_CODE);
        r.setMsg(msg);
        return r;
    }

    public static ResultData success(String msg, Object object){
        ResultData r = new ResultData();
        r.setCode(SUCCESS_CODE);
        r.setMsg(msg);
        r.setData(object);
        return r;
    }

    //    public static Result error()
    //    {
    //        Result r = new Result();
    //        r.setCode(ERROR_CODE);
    //        r.setMsg(ERROR_R);
    //        return r;
    //    }


//    public static Result error(Error error, String tip)
//    {
//        if (StringUtils.isNotBlank(tip) || StringUtils.isNotNull(tip))
//        {
//            tip = "，" + tip;
//        }
//        else
//        {
//            tip = "";
//        }
//        return error(error.getCode(), error.getErrMsg() + tip);
//    }

//    public static Result error(Error error)
//    {
//        return error(error, null);
//    }


    public static ResultData error(int code, String msg)
    {
        ResultData r = new ResultData();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
}
